package com.iss.demo.dao;

import com.iss.demo.entity.User;
import com.iss.demo.model.UserWithRole;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import java.util.List;

@Mapper
@Repository
public interface UserDao {
    @Select("select u_id,u_name,u_pwd,r_name,r_id from user inner join userrole on u_roleid=r_id where u_name=#{u_name} and u_pwd=#{u_pwd}")
    UserWithRole login(User user);

    @Select("select * from user inner join userrole on u_roleid=r_id")
    List<User>selectAll();

    @Select("select * from user where u_name=#{u_name}")
    public User checkUserNameExist(String u_name);

    @Insert("insert into user(u_name,u_pwd,u_roleid) VALUES (#{u_name},#{u_pwd},#{u_roleid})")
    Integer insert(User user);

    @Update("update user set u_name=#{u_name},u_pwd=#{u_pwd},u_roleid=#{u_roleid} where u_id=#{u_id}")
    Integer update(User user);

    @Delete("delete from user where u_id=#{u_id}")
    public Integer deleteOne(Integer u_id);

    @Select("select * from user where u_id=#{u_id}")
    public User selectByid(Integer id);
    

}

